package com.szq.netty.server;

import com.szq.netty.msg.Request;
import com.szq.netty.msg.Response;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;

/**
 * @ClassName: MyServerHandler
 * @Description:
 * @Author: szq
 * @Date: 2021-11-17 09:42:23
 */
public class MyServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        Request request = (Request) msg;
        //反馈
        Response response = new Response();
        response.setRequestId(request.getRequestId());
        response.setParam(request.getResult() + " 请求成功，反馈结果请接受处理。");
        ctx.writeAndFlush(response);
        //释放
        ReferenceCountUtil.release(request);
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx){
        ctx.flush();
    }
}
